package elsa.controller;

import java.io.File;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import elsa.bootmapper.UserMapper;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import elsa.bean.*;
import elsa.tools.*;
import elsa.bootmapper.ConstMapper;
import elsa.bootmapper.DocMapper;
import elsa.bootmapper.LogMapper;
import com.github.pagehelper.PageHelper;

@Controller
public class ConstController {

	@Autowired
	private ConstMapper constMapper;

	@Autowired
	private UserMapper userMapper;

	@Autowired
	private DocMapper docMapper;

	@Autowired
	private LogMapper logMapper;

	/*
	 * 建造检验操作
	 */
	//信息提醒 搜索 兼 分页
	@CrossOrigin
	@RequestMapping(value="/reminder/const", method = RequestMethod.GET)
	@ResponseBody
	@RequiresPermissions("public")
	public MyResp constInfoReminder(@RequestParam("pageIndex") Integer pageIndex,
									@RequestParam("pageSize") Integer pageSize,
									@RequestParam(value="value",required = false,defaultValue = "null") String value,
									@RequestParam(value="type",required = false,defaultValue = "null") String type){
		if(pageIndex==null){
			pageIndex=1;
		}
		if(pageSize==null){
			pageSize=10;
		}
		Subject subject = SecurityUtils.getSubject();
		ScsUser scsUser =(ScsUser) subject.getPrincipal();
		String id = scsUser.getUserid();
		String Role = userMapper.findRole(scsUser.getUserid()).getRole();
		switch (Role){
			case "管理员":
			case "负责人":
				PageHelper.startPage(pageIndex, pageSize);
				switch (type){
					case "inspnum":
						return  MyResp.render(0,"获取成功",constMapper.constInfoReminderByInspnum(value),constMapper.constInfoReminderCountByInspnum(value));
					case "shipname":
						return  MyResp.render(0,"获取成功",constMapper.constInfoReminderByShipname(value),constMapper.constInfoReminderCountByShipname(value));
					case "":
						return MyResp.render(0,"获取成功",constMapper.constInfoReminder(),constMapper.constInfoReminderCount());
					default:
						return MyResp.render(0,"获取成功",constMapper.constInfoReminder(),constMapper.constInfoReminderCount());
				}
			case "验船师":
				PageHelper.startPage(pageIndex, pageSize);
				switch (type){
					case "inspnum":
						return  MyResp.render(0,"获取成功",constMapper.constYcsInfoReminderByInspnum(value, id),constMapper.constYcsInfoReminderCountByInspnum(value, id));
					case "shipname":
						return  MyResp.render(0,"获取成功",constMapper.constYcsInfoReminderByShipname(value, id),constMapper.constYcsInfoReminderCountByShipname(value, id));
					case "":
						return MyResp.render(0,"获取成功",constMapper.constYcsInfoReminder(id),constMapper.constYcsInfoReminderCount(id));
					default:
						return MyResp.render(0,"获取成功",constMapper.constYcsInfoReminder(id),constMapper.constYcsInfoReminderCount(id));
				}
			case "船厂"	:
				PageHelper.startPage(pageIndex, pageSize);
				switch (type){
					case "inspnum":
						return  MyResp.render(0,"获取成功",constMapper.constCcInfoReminderByInspnum(value, id),constMapper.constCcInfoReminderCountByInspnum(value, id));
					case "shipname":
						return  MyResp.render(0,"获取成功",constMapper.constCcInfoReminderByShipname(value, id),constMapper.constCcInfoReminderCountByShipname(value, id));
					case "":
						return MyResp.render(0,"获取成功",constMapper.constCcInfoReminder(id),constMapper.constCcInfoReminderCount(id));
					default:
						return MyResp.render(0,"获取成功",constMapper.constCcInfoReminder(id),constMapper.constCcInfoReminderCount(id));
				}
			case "船东"	:
				PageHelper.startPage(pageIndex, pageSize);
				switch (type){
					case "inspnum":
						return  MyResp.render(0,"获取成功",constMapper.constCdInfoReminderByInspnum(value,id),constMapper.constCdInfoReminderCountByInspnum(value,id));
					case "shipname":
						return  MyResp.render(0,"获取成功",constMapper.constCdInfoReminderByShipname(value,id),constMapper.constCdInfoReminderCountByShipname(value,id));
					case "":
						return MyResp.render(0,"获取成功",constMapper.constCdInfoReminder(id),constMapper.constCdInfoReminderCount(id));
					default:
						return MyResp.render(0,"获取成功",constMapper.constCdInfoReminder(id),constMapper.constCdInfoReminderCount(id));
				}
			default:
				return null;
		}
	}

	//建造检验历史查询 兼 搜索  兼 分页
	@CrossOrigin
	@RequestMapping(value="/project/const/history", method = RequestMethod.GET)
	@ResponseBody
	@RequiresPermissions("public")
	public MyResp constHistoryList(@RequestParam("pageIndex") Integer pageIndex,
							@RequestParam("pageSize") Integer pageSize,
							@RequestParam(value="value",required = false,defaultValue = "null") String value,
							@RequestParam(value="type",required = false,defaultValue = "null") String type){
		if(pageIndex==null){
			pageIndex=1;
		}
		if(pageSize==null){
			pageSize=10;
		}
		PageHelper.startPage(pageIndex, pageSize);
		switch (type){
			case "inspnum":
				return MyResp.render(0,"获取成功",constMapper.historyInspnumConst(value),constMapper.historyInspnumConstCount(value));
			case "shipname":
				return MyResp.render(0,"获取成功",constMapper.historyShipnameConst(value),constMapper.historyShipnameConstCount(value));
			case "":
				return MyResp.render(0,"获取成功",constMapper.historyAllConst(),constMapper.historyAllConstCount());
			default:
				return MyResp.render(0,"获取成功",constMapper.historyAllConst(),constMapper.historyAllConstCount());
		}
	}

	//查询所有建造检验 兼 搜索  兼 分页
	@CrossOrigin
	@RequestMapping(value="/project/const/all", method = RequestMethod.GET)
	@ResponseBody
	@RequiresPermissions("public")
	public MyResp constlist(@RequestParam("pageIndex") Integer pageIndex,
							@RequestParam("pageSize") Integer pageSize,
							@RequestParam(value="value",required = false,defaultValue = "null") String value,
							@RequestParam(value="type",required = false,defaultValue = "null") String type){
		if(pageIndex==null){
			pageIndex=1;
		}
		if(pageSize==null){
			pageSize=10;
		}
		Subject subject = SecurityUtils.getSubject();
		ScsUser scsUser =(ScsUser) subject.getPrincipal();
		String id = scsUser.getUserid();
		String Role = userMapper.findRole(scsUser.getUserid()).getRole();
		switch (Role){
			case "管理员":
			case "负责人":
				PageHelper.startPage(pageIndex, pageSize);
				switch (type){
					case "inspnum":
						return  MyResp.render(0,"获取成功",constMapper.findAllConstByInspnum(value),constMapper.findConstCountByInspnum(value));
					case "shipname":
						return  MyResp.render(0,"获取成功",constMapper.findAllConstByShipname(value),constMapper.findConstCountByShipname(value));
					case ""	:
						return MyResp.render(0,"获取成功",constMapper.findAllConst(),constMapper.findConstCount());
					default:
						return MyResp.render(0,"获取成功",constMapper.findAllConst(),constMapper.findConstCount());
				}
			case "验船师":
				PageHelper.startPage(pageIndex, pageSize);
				switch (type){
					case "inspnum":
						return  MyResp.render(0,"获取成功",constMapper.findYcsConstByInspnum(value, id),constMapper.findYcsConstCountByInspnum(value, id));
					case "shipname":
						return  MyResp.render(0,"获取成功",constMapper.findYcsConstByShipname(value, id),constMapper.findYcsConstCountByShipname(value, id));
					case ""	:
						return MyResp.render(0,"获取成功",constMapper.findYcsConst(id),constMapper.findYcsConstCount(id));
					default:
						return MyResp.render(0,"获取成功",constMapper.findYcsConst(id),constMapper.findYcsConstCount(id));
				}
			case "船厂"	:
				PageHelper.startPage(pageIndex, pageSize);
				switch (type){
					case "inspnum":
						return  MyResp.render(0,"获取成功",constMapper.findCcConstByInspnum(value, id),constMapper.findCcConstCountByInspnum(value, id));
					case "shipname":
						return  MyResp.render(0,"获取成功",constMapper.findCcConstByShipname(value, id),constMapper.findCcConstCountByShipname(value, id));
					case ""	:
						return MyResp.render(0,"获取成功",constMapper.findCcConst(id),constMapper.findCcConstCount(id));
					default:
						return MyResp.render(0,"获取成功",constMapper.findCcConst(id),constMapper.findCcConstCount(id));
				}
			case "船东"	:
				PageHelper.startPage(pageIndex, pageSize);
				switch (type){
					case "inspnum":
						return  MyResp.render(0,"获取成功",constMapper.findCdConstByInspnum(value, id),constMapper.findCdConstCountByInspnum(value, id));
					case "shipname":
						return  MyResp.render(0,"获取成功",constMapper.findCdConstByShipname(value, id),constMapper.findCdConstCountByShipname(value, id));
					case ""	:
						return MyResp.render(0,"获取成功",constMapper.findCdConst(id),constMapper.findCdConstCount(id));
					default:
						return MyResp.render(0,"获取成功",constMapper.findCdConst(id),constMapper.findCdConstCount(id));
				}
			default:
				return null;
		}
	}

	//建造检验会议
	@CrossOrigin
	@RequestMapping(value="/project/const/meeting/{inspnum}", method = RequestMethod.GET)
	@ResponseBody
	@RequiresPermissions("public")
	public GroupMess constmeeting(@PathVariable("inspnum") String inspnum){
		if(inspnum==null){
			inspnum="";
		}
		if(constMapper.findConstByInspnum(inspnum)!=null){
			ScsConstinsp scsConstinsp = constMapper.findConstByInspnum(inspnum);
			String a[] = scsConstinsp.getCcinfo().split("/");
			String ccusername = a[1];
			String ccname = a[0];
			if(scsConstinsp.getCdname()==null){
				scsConstinsp.setCdname("");
			}
			if(scsConstinsp.getCdusername()==null){
				scsConstinsp.setCdusername("");
			}
			if(scsConstinsp.getCtname()==null){
				scsConstinsp.setCtname("");
			}
			if(scsConstinsp.getCtusername()==null){
				scsConstinsp.setCtusername("");
			}
			if(scsConstinsp.getLjname()==null){
				scsConstinsp.setLjname("");
			}
			if(scsConstinsp.getLjusername()==null){
				scsConstinsp.setLjusername("");
			}
			if(scsConstinsp.getDqname()==null){
				scsConstinsp.setDqname("");
			}
			if(scsConstinsp.getDqusername()==null){
				scsConstinsp.setDqusername("");
			}
			return GroupMess.reder(scsConstinsp.getCdname(),scsConstinsp.getCdusername(), scsConstinsp.getCtname(), scsConstinsp.getCtusername(), scsConstinsp.getLjname(), scsConstinsp.getLjusername(), scsConstinsp.getDqname(), scsConstinsp.getDqusername(), ccname, ccusername);
		}else {
			return GroupMess.reder("","","","","","","","","","");
		}
	}

	//查询建造检验信息
	@CrossOrigin
	@RequestMapping(value="/project/const/{inspnum}", method = RequestMethod.GET)
	@ResponseBody
	@RequiresPermissions("public")
	public ScsConstinsp constInfo(@PathVariable("inspnum") String inspnum){
		if(inspnum==null){
			inspnum="";
		}
		return constMapper.findConstByInspnum(inspnum);
	}

	//打印建造检验申请表
    @CrossOrigin
	@RequestMapping(value="/project/const/print/{inspnum}", method = RequestMethod.GET)
	@ResponseBody
	@RequiresPermissions("public")
	public ScsConstinsp printConstInfo(@PathVariable("inspnum") String inspnum){
		if(inspnum==null){
			inspnum="";
		}
		return constMapper.printConstByInspnum(inspnum);
	}

	//新建建造检验-船厂提交
	@CrossOrigin
	@RequestMapping(value = "/project/const/new/cc",method = RequestMethod.POST)
	@ResponseBody
	@RequiresPermissions(value = {"shipyard","admin"},logical= Logical.OR)
	public Message addConst(@RequestBody ScsConstinsp scsConstinsp){
		return new Message(setAddConst(scsConstinsp));
	}

	//更新建造检验-船厂提交
	@CrossOrigin
	@RequestMapping(value = "/project/const/update/cc", method = RequestMethod.PUT)
	@ResponseBody
	@RequiresPermissions(value = {"shipyard","admin","head"},logical= Logical.OR)
	public Message updateConst(@RequestBody ScsConstinsp scsConstinsp){
		return new Message(setUpdateConst(scsConstinsp));
	}

	//更新建造检验-船检处审核
	@CrossOrigin
	@RequestMapping(value = "/project/const/update/cjc", method = RequestMethod.PUT)
	@ResponseBody
	@RequiresPermissions(value = {"admin","head"},logical= Logical.OR)
	public Message updateConstCjc(@RequestBody ScsConstinsp scsConstinsp){
		return new Message(setUpdateConstCjc(scsConstinsp));
	}

	//禁用建造检验
    @CrossOrigin
	@RequestMapping(value = "/project/const/forbid/{inspnum}", method = RequestMethod.PUT)
	@ResponseBody
	@RequiresPermissions("admin")
	public Message forbidConst(@PathVariable("inspnum") String inspnum){
		return new Message(setForbidConst(inspnum));
	}

	//恢复建造检验
    @CrossOrigin
	@RequestMapping(value = "/project/const/renew/{inspnum}", method = RequestMethod.PUT)
	@ResponseBody
	@RequiresPermissions("admin")
	public Message renewConst(@PathVariable("inspnum") String inspnum){
		return new Message(setRenewConst(inspnum));
	}

	//删除建造检验
    @CrossOrigin
	@RequestMapping(value = "/project/const/delete/{inspnum}", method = RequestMethod.PUT)
	@ResponseBody
	@RequiresPermissions("admin")
	public Message deleteConst(@PathVariable("inspnum") String inspnum){
		return new Message(setDeleteConst(inspnum));
	}

	/*
     * 报检单操作
     */
	//查询报检单列表 兼 分页
	@CrossOrigin
	@RequestMapping(value="/project/const/inspdclr/{inspnum}", method = RequestMethod.GET)
	@ResponseBody
	@RequiresPermissions("public")
	public MyResp inspdclrAlllist(@PathVariable("inspnum") String inspnum,
								  @RequestParam("pageIndex") Integer pageIndex,
								  @RequestParam("pageSize") Integer pageSize,
								  @RequestParam(value="value",required = false,defaultValue = "null") String value,
								  @RequestParam(value="type",required = false,defaultValue = "null") String type){
		if(pageIndex==null){
			pageIndex=1;
		}
		if(pageSize==null){
			pageSize=10;
		}
		if(inspnum==null){
			inspnum="";
		}
		PageHelper.startPage(pageIndex, pageSize);
		switch (type){
			case "inspname":
				return	MyResp.render(0, "获取成功", constMapper.findByInspdclr(inspnum,value), constMapper.findInspdclrByCount(inspnum,value));
			case "":
				return	MyResp.render(0, "获取成功", constMapper.findAllInspdclr(inspnum), constMapper.findInspdclrCount(inspnum));
			default:
				return	MyResp.render(0, "获取成功", constMapper.findAllInspdclr(inspnum), constMapper.findInspdclrCount(inspnum));
		}
	}

	//历史查询报检单列表 兼 分页
	@CrossOrigin
	@RequestMapping(value="/history/const/inspdclr/{inspnum}", method = RequestMethod.GET)
	@ResponseBody
	@RequiresPermissions("public")
	public MyResp inspdclrHiAlllist(@PathVariable("inspnum") String inspnum,
								  @RequestParam("pageIndex") Integer pageIndex,
								  @RequestParam("pageSize") Integer pageSize,
								  @RequestParam(value="value",required = false,defaultValue = "null") String value,
								  @RequestParam(value="type",required = false,defaultValue = "null") String type){
		if(pageIndex==null){
			pageIndex=1;
		}
		if(pageSize==null){
			pageSize=10;
		}
		if(inspnum==null){
			inspnum="";
		}
		PageHelper.startPage(pageIndex, pageSize);
		switch (type){
			case "inspname":
				return	MyResp.render(0, "获取成功", constMapper.findHiByInspdclr(inspnum,value), constMapper.findHiInspdclrByCount(inspnum,value));
			case "":
				return	MyResp.render(0, "获取成功", constMapper.findHiAllInspdclr(inspnum), constMapper.findHiInspdclrCount(inspnum));
			default:
				return	MyResp.render(0, "获取成功", constMapper.findHiAllInspdclr(inspnum), constMapper.findHiInspdclrCount(inspnum));
		}
	}

	//查询报检单信息
    @CrossOrigin
	@RequestMapping(value="/project/const/inspdclr/info", method = RequestMethod.GET)
	@ResponseBody
	@RequiresPermissions("public")
	public ScsInspdclr inspdclrInfo(@RequestParam("inspnum") String inspnum,@RequestParam("inspdate") String inspdate){
		if(inspnum==null){
			inspnum="";
		}
		if(inspdate==null){
			inspdate="";
		}
		return  constMapper.findIdByInspnum(inspnum, inspdate);
	}

	//打印报检单信息
    @CrossOrigin
	@RequestMapping(value="/project/const/inspdclr/print", method = RequestMethod.GET)
	@ResponseBody
	@RequiresPermissions("public")
	public ScsInspdclr inspdclrPrint(@RequestParam("inspnum") String inspnum,@RequestParam("inspdate") String inspdate){
		if(inspnum==null){
			inspnum="";
		}
		if(inspdate==null){
			inspdate="";
		}
		return constMapper.printIdByInspnum(inspnum, inspdate);
	}

	//打印船舶质量检验控制表信息
    @CrossOrigin
	@RequestMapping(value="/project/const/sqcc/print", method = RequestMethod.GET)
	@ResponseBody
	@RequiresPermissions("public")
	public ScsInspdclr sqccPrint(@RequestParam("inspnum") String inspnum,@RequestParam("inspdate") String inspdate){
		if(inspnum==null){
			inspnum="";
		}
		if(inspdate==null){
			inspdate="";
		}
		return constMapper.printSqccByInspnum(inspnum, inspdate);
	}

	//新建报检单-船厂提交
	@CrossOrigin
	@RequestMapping(value = "/project/const/inspdclr/new/cc",method = RequestMethod.POST)
	@ResponseBody
	@RequiresPermissions(value = {"admin","shipyard"},logical= Logical.OR)
	public Message addInspdclrCc(@RequestBody ScsInspdclr scsInspdclr){
		return new Message(setAddInspdclrCc(scsInspdclr));
	}

	//更新报检单-船厂提交
	@CrossOrigin
	@RequestMapping(value = "/project/const/inspdclr/update/cc", method = RequestMethod.PUT)
	@ResponseBody
	@RequiresPermissions(value = {"admin","shipyard"},logical= Logical.OR)
	public Message updateInspdclrCc(@RequestBody ScsInspdclr scsInspdclr){
		return new Message(setUpdateInspdclrCc(scsInspdclr));
	}

	//更新报检单-船东审核
	@CrossOrigin
	@RequestMapping(value = "/project/const/inspdclr/update/cd", method = RequestMethod.PUT)
	@ResponseBody
	@RequiresPermissions(value = {"shipowner","admin"},logical= Logical.OR)
	public Message updateInspdclrCd(@RequestBody ScsInspdclr scsInspdclr){
		return new Message(setUpdateInspdclrCd(scsInspdclr));
	}

	//更新报检单-验船师确认
	@CrossOrigin
	@RequestMapping(value = "/project/const/inspdclr/update/ycsconfirm", method = RequestMethod.PUT)
	@ResponseBody
	@RequiresPermissions(value = {"surveyor","admin"},logical= Logical.OR)
	public Message updateInspdclrYcsconfirm(@RequestBody ScsInspdclr scsInspdclr){
		return new Message(setUpdateInspdclrYcsconfirm(scsInspdclr));
	}

	//更新报检单-验船师检验
	@CrossOrigin
	@RequestMapping(value = "/project/const/inspdclr/update/ycscheck", method = RequestMethod.PUT)
	@ResponseBody
	@RequiresPermissions(value = {"surveyor","admin"},logical= Logical.OR)
	public Message updateInspdclrYcscheck(@RequestBody ScsInspdclr scsInspdclr){
		return new Message(setUpdateInspdclrYcscheck(scsInspdclr));
	}

	//更新报检单-验船师检验-船厂意见
	@CrossOrigin
	@RequestMapping(value = "/project/const/inspdclr/update/idccopn", method = RequestMethod.PUT)
	@ResponseBody
	@RequiresPermissions(value = {"shipyard","admin"},logical= Logical.OR)
	public Message updateIdCcopn(@RequestBody ScsInspdclr scsInspdclr){
		return new Message(setUpdateIdCcopn(scsInspdclr));
	}

	//更新报检单-验船师检验-船东意见
	@CrossOrigin
	@RequestMapping(value = "/project/const/inspdclr/update/idcdopn", method = RequestMethod.PUT)
	@ResponseBody
	@RequiresPermissions(value = {"shipowner","admin"},logical= Logical.OR)
	public Message updateIdCdopn(@RequestBody ScsInspdclr scsInspdclr){
		return new Message(setUpdateIdCdopn(scsInspdclr));
	}

	//删除报检单
	@CrossOrigin
	@RequestMapping(value = "/project/const/inspdclr/delete", method = RequestMethod.PUT)
	@ResponseBody
	@RequiresPermissions("admin")
	public Message deleteInspdclr(@RequestParam("inspnum") String inspnum, @RequestParam("inspdate") String inspdate){
		return new Message(setDeleteId(inspnum, inspdate));
	}

	/*
	 * 基本操作
	 */
	//新增建造检验-船厂提交
	private String setAddConst(ScsConstinsp scsConstinsp){
		String b;
//		if(scsConstinsp.getInspnum()!=null&&constMapper.findConstByInspnum(scsConstinsp.getInspnum())!=null&&constMapper.findConstByInspnum(scsConstinsp.getInspnum()).getAuditstate().equals("不予受理")){
//			if(!setDeleteConst(scsConstinsp.getInspnum()).equals("删除建造检验成功!")){
//				b = "创建失败!";
//				return b;
//			}
//		}
		scsConstinsp.setInspnum("sqb"+getSqbnum());
		if(scsConstinsp.getCdinfo()!=null&&scsConstinsp.getCdinfo().equals("")){
			scsConstinsp.setCdname("");
			scsConstinsp.setCdusername("");
		}else if(scsConstinsp.getCdinfo()==null||!chickPeopleInfo(scsConstinsp.getCdinfo())){
			scsConstinsp.setCdinfo("cdinfo");
			scsConstinsp.setCdname("");
			scsConstinsp.setCdusername("");
		}else {
			String a[] = scsConstinsp.getCdinfo().split("/");
			scsConstinsp.setCdname(a[0]);
			scsConstinsp.setCdusername(a[1]);
		}
		if(scsConstinsp.getInspnum()!=null&&constMapper.findConstByInspnum(scsConstinsp.getInspnum())!=null){
			b = "此项目已存在!";
		}else if (scsConstinsp.getShipname()==null||!chickShipname(scsConstinsp.getShipname().trim())) {
			b = "船名填写格式错误!";
		}else if (scsConstinsp.getInsptype()==null||!chickInsptype(scsConstinsp.getInsptype())) {
			b = "检验类型填写错误!";
		}else if (scsConstinsp.getShiplength()==null||!chickNumber(scsConstinsp.getShiplength())) {
			b = "总长填写格式错误!";
		}else if (scsConstinsp.getGrosston()==null||!chickGrosston(scsConstinsp.getGrosston())) {
			b = "总吨位填写格式错误!";
		}else if (scsConstinsp.getHostpower()==null||!chickNumber(scsConstinsp.getHostpower())) {
			b = "主机功率填写格式错误!";
		}else if (scsConstinsp.getRegion()==null||!chickRegion(scsConstinsp.getRegion())) {
			b = "航行区域填写错误!";
		}else if (scsConstinsp.getShipstops()==null||!chickShipstops(scsConstinsp.getShipstops())) {
			b = "船籍港填写格式错误!";
		}else if (scsConstinsp.getShiptype()==null||!chickName(scsConstinsp.getShiptype())) {
			b = "船舶类型填写格式错误!";
		}else if (scsConstinsp.getDesignunit()==null||(!scsConstinsp.getDesignunit().equals("")&&!chickName(scsConstinsp.getDesignunit()))) {
			b = "设计单位填写格式错误!";
		}else if (scsConstinsp.getFigurenum()==null||!chickNum(scsConstinsp.getFigurenum())) {
			b = "图号类型填写格式错误!";
		}else if (scsConstinsp.getApprovalnum()==null||(!scsConstinsp.getApprovalnum().equals("")&&!chickNum(scsConstinsp.getApprovalnum()))) {
			b = "审图批准号填写格式错误!";
		}else if (scsConstinsp.getFiguredate()!=null&&!chickDate(scsConstinsp.getFiguredate())) {
			b = "图纸批准日期填写格式错误!";
		}else if (scsConstinsp.getFiguredate()!=null&&!compareTime(scsConstinsp.getFiguredate(),0)) {
			b = "图纸批准日期不能在当天之后!";
		}else if (scsConstinsp.getSchddate()==null||!chickDate(scsConstinsp.getSchddate())) {
			b = "预计开工时间填写格式错误!";
		}else if (!compareTime(scsConstinsp.getSchddate(),1)) {
			b = "预计开工时间不能在当天之前!";
		}else if (!scsConstinsp.getCdinfo().equals("")&&(scsConstinsp.getCdusername().equals("")||scsConstinsp.getCdname().equals("")||userMapper.validateCd(scsConstinsp.getCdusername(), scsConstinsp.getCdname())==null)) {
			b = "船东信息填写错误!";
		}else if (scsConstinsp.getCcpronum()==null||!chickNum(scsConstinsp.getCcpronum())){
			b = "船厂工程编号格式填写错误!";
		}else if(scsConstinsp.getInfo1()==null||scsConstinsp.getInfo1num()==null||scsConstinsp.getInfo1adr()==null||scsConstinsp.getInfo2()==null||scsConstinsp.getInfo2num()==null||scsConstinsp.getInfo2adr()==null||scsConstinsp.getInfo3()==null||scsConstinsp.getInfo3adr()==null||scsConstinsp.getInfo4()==null||scsConstinsp.getInfo4name()==null||scsConstinsp.getInfo4adr()==null){
			b = "提交资料填写错误";
		}else if(!scsConstinsp.getInfo1()&&(scsConstinsp.getInfo1num()!=0||!scsConstinsp.getInfo1adr().equals(""))){
			b = "提交资料填写错误!";
		}else if(!scsConstinsp.getInfo2()&&(scsConstinsp.getInfo2num()!=0||!scsConstinsp.getInfo2adr().equals(""))){
			b = "提交资料填写错误!";
		}else if(!scsConstinsp.getInfo3()&&(!scsConstinsp.getInfo3adr().equals(""))){
			b = "提交资料填写错误!";
		}else if(!scsConstinsp.getInfo4()&&(!scsConstinsp.getInfo4name().equals("")||!scsConstinsp.getInfo4adr().equals(""))){
			b = "提交资料填写错误!";
		}else if(scsConstinsp.getInfo1()&&(scsConstinsp.getInfo1num()==0||scsConstinsp.getInfo1adr().equals(""))){
			b = "提交资料填写错误!";
		}else if(scsConstinsp.getInfo2()&&(scsConstinsp.getInfo2num()==0||scsConstinsp.getInfo2adr().equals(""))){
			b = "提交资料填写错误!";
		}else if(scsConstinsp.getInfo3()&&(scsConstinsp.getInfo3adr().equals(""))){
			b = "提交资料填写错误!";
		}else if(scsConstinsp.getInfo4()&&(scsConstinsp.getInfo4name().equals("")||scsConstinsp.getInfo4adr().equals(""))){
			b = "提交资料填写错误!";
		}else if (scsConstinsp.getApunitname()==null||(!scsConstinsp.getApunitname().equals("")&&!chickName(scsConstinsp.getApunitname()))) {
			b = "申请单位名称填写格式错误!";
		}else if (scsConstinsp.getFax()==null||(!scsConstinsp.getFax().equals("")&&!chickFax(scsConstinsp.getFax()))) {
			b = "传真填写格式错误!";
		}else if (scsConstinsp.getZipcode()==null||(!scsConstinsp.getZipcode().equals("")&&!chickZipcode(scsConstinsp.getZipcode()))) {
			b = "邮编填写格式错误!";
		}else if (scsConstinsp.getCrecode()==null||(!scsConstinsp.getCrecode().equals("")&&!chickCrecode(scsConstinsp.getCrecode()))) {
			b = "社会统一代码填写格式错误!";
		}else if (scsConstinsp.getCcadr()==null||(!scsConstinsp.getCcadr().equals("")&&!chickCcadr(scsConstinsp.getCcadr()))) {
			b = "地址填写格式错误!";
		}else if (scsConstinsp.getWritename()==null||(!scsConstinsp.getWritename().equals("")&&!chickName(scsConstinsp.getWritename()))) {
			b = "负责人格式错误!";
		}else if(scsConstinsp.getCcinfo()==null||!chickCcInfo(scsConstinsp.getCcinfo())){
			b = "联系人和电话格式错误!";
		}else {
			scsConstinsp.setShipname(scsConstinsp.getShipname().trim());
			if(!scsConstinsp.getCdusername().equals("")){
				String cdid = userMapper.findByUsername(scsConstinsp.getCdusername()).getUserid();
				scsConstinsp.setCdid(cdid);
				userJoinPro(cdid,"船东");
			}
			String c[] = scsConstinsp.getCcinfo().split("/");
			if(c[1]!=null&&userMapper.findByUsername(c[1])!=null){
				String ccid = userMapper.findByUsername(c[1]).getUserid();
				scsConstinsp.setCcid(ccid);
				userJoinPro(ccid, "船厂");
			}
			Method method = new Method();
			if(scsConstinsp.getInfo1()){
				method.copyFile(scsConstinsp.getInfo1adr(),"const/"+scsConstinsp.getInspnum()+"/constfile1"+scsConstinsp.getInfo1adr().substring(scsConstinsp.getInfo1adr().lastIndexOf("/")));
				scsConstinsp.setInfo1adr("const/"+scsConstinsp.getInspnum()+"/constfile1"+scsConstinsp.getInfo1adr().substring(scsConstinsp.getInfo1adr().lastIndexOf("/")));
			}
			if(scsConstinsp.getInfo2()){
				method.copyFile(scsConstinsp.getInfo2adr(),"const/"+scsConstinsp.getInspnum()+"/constfile2"+scsConstinsp.getInfo2adr().substring(scsConstinsp.getInfo2adr().lastIndexOf("/")));
				scsConstinsp.setInfo2adr("const/"+scsConstinsp.getInspnum()+"/constfile2"+scsConstinsp.getInfo2adr().substring(scsConstinsp.getInfo2adr().lastIndexOf("/")));
			}
			if(scsConstinsp.getInfo3()){
				method.copyFile(scsConstinsp.getInfo3adr(),"const/"+scsConstinsp.getInspnum()+"/constfile3"+scsConstinsp.getInfo3adr().substring(scsConstinsp.getInfo3adr().lastIndexOf("/")));
				scsConstinsp.setInfo3adr("const/"+scsConstinsp.getInspnum()+"/constfile3"+scsConstinsp.getInfo3adr().substring(scsConstinsp.getInfo3adr().lastIndexOf("/")));
			}
			if(scsConstinsp.getInfo4()){
				method.copyFile(scsConstinsp.getInfo4adr(),"const/"+scsConstinsp.getInspnum()+"/constfile4"+scsConstinsp.getInfo4adr().substring(scsConstinsp.getInfo4adr().lastIndexOf("/")));
				scsConstinsp.setInfo4adr("const/"+scsConstinsp.getInspnum()+"/constfile4"+scsConstinsp.getInfo4adr().substring(scsConstinsp.getInfo4adr().lastIndexOf("/")));
			}
			scsConstinsp.setWritedate(getNtime());
			scsConstinsp.setLatesttime(getNtime());
			scsConstinsp.setState("未完成");
			scsConstinsp.setFlag("未完成");
			scsConstinsp.setAllstate("申请表船厂提交");
			scsConstinsp.setAlltime(getNtime());
			constMapper.saveConst(scsConstinsp);
			b = "创建成功!";
		}
		return b;
	}

	//更新建造检验-船厂提交
	private String setUpdateConst(ScsConstinsp scsConstinsp){
		String b;
		if(scsConstinsp.getCdinfo()!=null&&scsConstinsp.getCdinfo().equals("")){
			scsConstinsp.setCdname("");
			scsConstinsp.setCdusername("");
		}else if(scsConstinsp.getCdinfo()==null||!chickPeopleInfo(scsConstinsp.getCdinfo())){
			scsConstinsp.setCdinfo("cdinfo");
			scsConstinsp.setCdname("");
			scsConstinsp.setCdusername("");
		}else {
			String a[] = scsConstinsp.getCdinfo().split("/");
			scsConstinsp.setCdname(a[0]);
			scsConstinsp.setCdusername(a[1]);
		}
		if(scsConstinsp.getInspnum()!=null&&constMapper.findConstByInspnum(scsConstinsp.getInspnum())==null){
			b = "此项目不存在!";
		}else if (scsConstinsp.getShipname()==null||!chickShipname(scsConstinsp.getShipname().trim())) {
			b = "船名填写格式错误!";
		}else if (scsConstinsp.getInsptype()==null||!chickInsptype(scsConstinsp.getInsptype())) {
			b = "检验类型填写错误!";
		}else if (scsConstinsp.getShiplength()==null||!chickNumber(scsConstinsp.getShiplength())) {
			b = "总长填写格式错误!";
		}else if (scsConstinsp.getGrosston()==null||!chickGrosston(scsConstinsp.getGrosston())) {
			b = "总吨位填写格式错误!";
		}else if (scsConstinsp.getHostpower()==null||!chickNumber(scsConstinsp.getHostpower())) {
			b = "主机功率填写格式错误!";
		}else if (scsConstinsp.getRegion()==null||!chickRegion(scsConstinsp.getRegion())) {
			b = "航行区域填写错误!";
		}else if (scsConstinsp.getShipstops()==null||!chickShipstops(scsConstinsp.getShipstops())) {
			b = "船籍港填写格式错误!";
		}else if (scsConstinsp.getShiptype()==null||!chickName(scsConstinsp.getShiptype())) {
			b = "船舶类型填写格式错误!";
		}else if (scsConstinsp.getDesignunit()==null||(!scsConstinsp.getDesignunit().equals("")&&!chickName(scsConstinsp.getDesignunit()))) {
			b = "设计单位填写格式错误!";
		}else if (scsConstinsp.getFigurenum()==null||!chickNum(scsConstinsp.getFigurenum())) {
			b = "图号类型填写格式错误!";
		}else if (scsConstinsp.getApprovalnum()==null||(!scsConstinsp.getApprovalnum().equals("")&&!chickNum(scsConstinsp.getApprovalnum()))) {
			b = "审图批准号填写格式错误!";
		}else if (scsConstinsp.getFiguredate()!=null&&!chickDate(scsConstinsp.getFiguredate())) {
			b = "图纸批准日期填写格式错误!";
		}else if (scsConstinsp.getFiguredate()!=null&&!compareTime(scsConstinsp.getFiguredate(),0)) {
			b = "图纸批准日期不能在当天之后!";
		}else if (scsConstinsp.getSchddate()==null||!chickDate(scsConstinsp.getSchddate())) {
			b = "预计开工时间填写格式错误!";
		}else if (!scsConstinsp.getSchddate().equals(constMapper.findConstByInspnum(scsConstinsp.getInspnum()).getSchddate())&&!compareTime(scsConstinsp.getSchddate(),1)) {
			b = "预计开工时间不能在当天之前!";
		}else if (!scsConstinsp.getCdinfo().equals("")&&(scsConstinsp.getCdusername().equals("")||scsConstinsp.getCdname().equals("")||userMapper.validateCd(scsConstinsp.getCdusername(), scsConstinsp.getCdname())==null)) {
			b = "船东信息填写错误!";
		}else if (scsConstinsp.getCcpronum()==null||!chickNum(scsConstinsp.getCcpronum())){
			b = "船厂工程编号格式填写错误!";
		}else if (scsConstinsp.getApunitname()==null||(!scsConstinsp.getApunitname().equals("")&&!chickName(scsConstinsp.getApunitname()))) {
			b = "申请单位名称填写格式错误!";
		}else if (scsConstinsp.getFax()==null||(!scsConstinsp.getFax().equals("")&&!chickFax(scsConstinsp.getFax()))) {
			b = "传真填写格式错误!";
		}else if (scsConstinsp.getZipcode()==null||(!scsConstinsp.getZipcode().equals("")&&!chickZipcode(scsConstinsp.getZipcode()))) {
			b = "邮编填写格式错误!";
		}else if (scsConstinsp.getCrecode()==null||(!scsConstinsp.getCrecode().equals("")&&!chickCrecode(scsConstinsp.getCrecode()))) {
			b = "社会统一代码填写格式错误!";
		}else if (scsConstinsp.getCcadr()==null||(!scsConstinsp.getCcadr().equals("")&&!chickCcadr(scsConstinsp.getCcadr()))) {
			b = "地址填写格式错误!";
		}else if (scsConstinsp.getWritename()==null||(!scsConstinsp.getWritename().equals("")&&!chickName(scsConstinsp.getWritename()))) {
			b = "负责人格式错误!";
		}else if(scsConstinsp.getCcinfo()==null||!chickCcInfo(scsConstinsp.getCcinfo())){
			b = "联系人和电话格式错误!";
		}else {
			ScsConstinsp oldConst = constMapper.findConstByInspnum(scsConstinsp.getInspnum());
			userQuitPro(oldConst.getCdid(), "船东");
			userQuitPro(oldConst.getCcid(), "船厂");
			scsConstinsp.setShipname(scsConstinsp.getShipname().trim());
			if(!scsConstinsp.getCdusername().equals("")){
				String cdid = userMapper.findByUsername(scsConstinsp.getCdusername()).getUserid();
				scsConstinsp.setCdid(cdid);
				userJoinPro(cdid, "船东");
			}
			String c[] = scsConstinsp.getCcinfo().split("/");
			if(c[1]!=null&&userMapper.findByUsername(c[1]).getUserid()!=null){
				String ccid = userMapper.findByUsername(c[1]).getUserid();
				scsConstinsp.setCcid(ccid);
				userJoinPro(ccid, "船厂");
			}
			scsConstinsp.setWritedate(getNtime());
			scsConstinsp.setLatesttime(getNtime());
			scsConstinsp.setAlltime(getNtime());
			constMapper.updateConst(scsConstinsp);
			b = "更新成功!";
		}
		return b;
	}

	//更新建造检验-船检处审核
	private String setUpdateConstCjc(ScsConstinsp scsConstinsp){
		String b;
		if(scsConstinsp.getCtinfo()==null||scsConstinsp.getCtinfo().equals("")||!chickPeopleInfo(scsConstinsp.getCtinfo())){
			scsConstinsp.setCtinfo("");
			scsConstinsp.setCtname("");
			scsConstinsp.setCtusername("");
		}else {
			String c[] = scsConstinsp.getCtinfo().split("/");
			scsConstinsp.setCtname(c[0]);
			scsConstinsp.setCtusername(c[1]);
		}
		if(scsConstinsp.getLjinfo()==null||scsConstinsp.getLjinfo().equals("")||!chickPeopleInfo(scsConstinsp.getLjinfo())){
			scsConstinsp.setLjinfo("");
			scsConstinsp.setLjname("");
			scsConstinsp.setLjusername("");
		}else {
			String d[] = scsConstinsp.getLjinfo().split("/");
			scsConstinsp.setLjname(d[0]);
			scsConstinsp.setLjusername(d[1]);
		}
		if(scsConstinsp.getDqinfo()==null||scsConstinsp.getDqinfo().equals("")||!chickPeopleInfo(scsConstinsp.getDqinfo())){
			scsConstinsp.setDqinfo("");
			scsConstinsp.setDqname("");
			scsConstinsp.setDqusername("");
		}else {
			String e[] = scsConstinsp.getDqinfo().split("/");
			scsConstinsp.setDqname(e[0]);
			scsConstinsp.setDqusername(e[1]);
		}
		if(scsConstinsp.getAuditopn()==null){
			scsConstinsp.setAuditopn("");
		}
		if(scsConstinsp.getHeadman()==null||scsConstinsp.getHeadman()<0||scsConstinsp.getHeadman()>3){
			scsConstinsp.setHeadman(0);
		}
		if(scsConstinsp.getInspnum()==null||constMapper.findConstByInspnum(scsConstinsp.getInspnum())==null){
			b = "此项目不存在!";
		}else if (scsConstinsp.getAuditstate()==null||!chickAuditstate(scsConstinsp.getAuditstate())) {
			b = "受理状态填写格式错误!";
		}else if(scsConstinsp.getAinspnum()==null){
			b = "检验编号填写格式错误!";
		}else if(constMapper.findConstByInspnum(scsConstinsp.getAinspnum())!=null){
			b = "该检验编号项目已存在!";
		}else if (scsConstinsp.getAuditstate().equals("不予受理")&&!scsConstinsp.getAinspnum().equals("")) {
			b = "检验编号填写格式错误!";
		}else if (scsConstinsp.getAuditstate().equals("同意受理")&&constMapper.findConstByInspnum(scsConstinsp.getInspnum()).getAuditstate().equals("")&&(scsConstinsp.getAinspnum()==null||!chickInspnum(scsConstinsp.getAinspnum()))) {
			b = "检验编号填写格式错误!";
		}else if (!scsConstinsp.getCtinfo().equals("")&&userMapper.validateCtYcs(scsConstinsp.getCtusername(), scsConstinsp.getCtname())==null) {
			b = "船体成员信息填写错误!";
		}else if (!scsConstinsp.getLjinfo().equals("")&&userMapper.validateLjYcs(scsConstinsp.getLjusername(), scsConstinsp.getLjname())==null) {
			b = "轮机成员信息填写错误!";
		}else if (!scsConstinsp.getDqinfo().equals("")&&userMapper.validateDqYcs(scsConstinsp.getDqusername(), scsConstinsp.getDqname())==null) {
			b = "电气成员信息填写错误!";
		}else if(scsConstinsp.getAuditstate().equals("不予受理")&&scsConstinsp.getAuditopn().equals("")){
			b = "请填写审核意见!";
		}else if (scsConstinsp.getAuditstate().equals("同意受理")&&(scsConstinsp.getCtinfo().equals("")||scsConstinsp.getLjinfo().equals("")||scsConstinsp.getDqinfo().equals("")||scsConstinsp.getHeadman().equals(0))){
			b = "建造组成员信息错误!";
		}else {
			ScsConstinsp oldConst = constMapper.findConstByInspnum(scsConstinsp.getInspnum());
			if(oldConst.getCtid()!=null){
				userQuitPro(oldConst.getCtid(), "验船师");
			}
			if(oldConst.getLjid()!=null){
				userQuitPro(oldConst.getLjid(), "验船师");
			}
			if(oldConst.getDqid()!=null){
				userQuitPro(oldConst.getDqid(), "验船师");
			}
			if(!scsConstinsp.getCtusername().equals("")){
				String ctid = userMapper.findByUsername(scsConstinsp.getCtusername()).getUserid();
				scsConstinsp.setCtid(ctid);
				userJoinPro(ctid, "验船师");
			}
			if(!scsConstinsp.getLjusername().equals("")){
				String ljid = userMapper.findByUsername(scsConstinsp.getLjusername()).getUserid();
				scsConstinsp.setLjid(ljid);
				userJoinPro(ljid, "验船师");
			}
			if(!scsConstinsp.getDqusername().equals("")){
				String dqid = userMapper.findByUsername(scsConstinsp.getDqusername()).getUserid();
				scsConstinsp.setDqid(dqid);
				userJoinPro(dqid, "验船师");
			}
			if(scsConstinsp.getAuditstate().equals("不予受理")){
				scsConstinsp.setAllstate("申请表船检处审核不予受理");
				constMapper.uncompleteConst(scsConstinsp.getInspnum());	//更新建造检验状态-未完成
			}else{
				scsConstinsp.setAuditopn("");
				scsConstinsp.setAllstate("申请表船检处审核同意受理");
			}
			scsConstinsp.setAuditdate(getNtime());
			scsConstinsp.setLatesttime(getNtime());
			scsConstinsp.setAlltime(getNtime());
			if(!scsConstinsp.getAinspnum().equals("")){
				constMapper.updateConstCjcjy(scsConstinsp);
			}else {
				constMapper.updateConstCjc(scsConstinsp);
			}
			constMapper.updateAll(scsConstinsp);
			b = "更新成功!";
		}
		return b;
	}

	//禁用建造检验
	private String setForbidConst(String inspnum){
		String b;
		if(inspnum==null||constMapper.findConstByInspnum(inspnum)==null){
			b = "该项目不存在!";
		}else if (constMapper.findConstByInspnum(inspnum).getState().equals("禁用")) {
			b = "请勿重复操作!";
		}else {
			constMapper.forbidConst(inspnum);
			b = "禁用建造检验成功!";
		}
		return b;
	}

	//恢复建造检验
	private String setRenewConst(String inspnum){
		String b;
		if(inspnum==null||constMapper.findConstByInspnum(inspnum)==null){
			b = "该项目不存在!";
		}else if (!constMapper.findConstByInspnum(inspnum).getState().equals("禁用")) {
			b = "请勿重复操作!";
		}else {
			constMapper.renewConst(inspnum);
			b = "恢复建造检验成功!";
		}
		return b;
	}

	//删除建造检验
	private String setDeleteConst(String inspnum){
		String b;
		if(inspnum==null||constMapper.findConstByInspnum(inspnum)==null){
			b = "该项目不存在!";
		}else {
			Method method = new Method();
			String path = "const/"+inspnum;
			String classPath = this.getClass().getClassLoader().getResource("").getPath();
			String thepath = classPath.substring(0,classPath.indexOf("WEB-INF"))+"file/";
			path = thepath+path;
			File dir = new File(path);
			method.deleteDir(dir);				//删除所有文件
			constMapper.deleteConst(inspnum);	//删除建造检验申请表
			constMapper.deleteIdAll(inspnum);	//删除所有报检单
			docMapper.deleteDocAll(inspnum);	//删除所有文档
			logMapper.deleteLogAll(inspnum);	//删除所有日志
			b = "删除建造检验成功!";
		}
		return b;
	}

	//新建报检单-船厂提交
	private String setAddInspdclrCc(ScsInspdclr scsInspdclr){
		String b;
		Date date = new Date();
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String str = format.format(date);
		scsInspdclr.setInspdate(str);
		if (scsInspdclr.getInspnum()==null||!chickInspnum(scsInspdclr.getInspnum())){
			b = "检验编号填写格式错误!";
		}else if(scsInspdclr.getApnttime()==null||!chickDate(scsInspdclr.getApnttime())){
			b = "预约检验时间格式填写错误!";
		}else if(!compareTime(scsInspdclr.getApnttime(),1)){
			b = "预约检验时间不能在当天之前!";
		}else if (scsInspdclr.getInspname()==null||!chickInspname(scsInspdclr.getInspname())){
			b = "报检单名称格式填写错误!";
		}else if(scsInspdclr.getInsppro()==null||scsInspdclr.getInsppro().equals("")){
			b = "报检项目格式填写错误!";
		}else if(scsInspdclr.getCc()==null||!chickPeoplename(scsInspdclr.getCc())){
			b = "船厂检验员格式填写错误!";
		}else if(scsInspdclr.getInspnum()==null||scsInspdclr.getInspdate()==null||constMapper.findIdByInspnum(scsInspdclr.getInspnum(), scsInspdclr.getInspdate())!=null){
			b = "该报检单已存在!";
		}else{
			scsInspdclr.setIdlatesttime(getNtime());
			scsInspdclr.setRq1(getNtime());
			scsInspdclr.setIdstate("船厂已提交");
			ScsConstinsp scsConstinsp = new ScsConstinsp();
			scsConstinsp.setInspnum(scsInspdclr.getInspnum());
			scsConstinsp.setAllstate("报检单船厂已提交");
			scsConstinsp.setAlltime(getNtime());
			constMapper.uncompleteConst(scsInspdclr.getInspnum());
			constMapper.saveIdCc(scsInspdclr);
			constMapper.updateAll(scsConstinsp);
			b = "创建成功!";
		}
		return b;
	}

	//更新报检单-船厂提交
	private String setUpdateInspdclrCc(ScsInspdclr scsInspdclr){
		String b;
		if(scsInspdclr.getInspnum()==null||scsInspdclr.getInspdate()==null||constMapper.findIdByInspnum(scsInspdclr.getInspnum(), scsInspdclr.getInspdate())==null){
			b = "此项目不存在!";
		}else if (scsInspdclr.getInspnum()==null||!chickInspnum(scsInspdclr.getInspnum())){
			b = "检验编号填写格式错误!";
		}else if (scsInspdclr.getInspname()==null||!chickInspname(scsInspdclr.getInspname())){
			b = "报检单名称格式填写错误!";
		}else if(scsInspdclr.getApnttime()==null||!chickDate(scsInspdclr.getApnttime())){
			b = "预约检验时间格式填写错误!";
		}else if(!scsInspdclr.getApnttime().equals(constMapper.findIdByInspnum(scsInspdclr.getInspnum(), scsInspdclr.getInspdate()).getApnttime())&&!compareTime(scsInspdclr.getApnttime(),1)){
			b = "预约检验时间不能在当天之前!";
		}else if(scsInspdclr.getInsppro()==null){
			b = "报检项目填写错误!";
		}else if(scsInspdclr.getCc()==null||!chickPeoplename(scsInspdclr.getCc())){
			b = "船厂检验员填写错误!";
		}else {
			scsInspdclr.setIdlatesttime(getNtime());
			scsInspdclr.setRq1(getNtime());
			constMapper.updateIdCc(scsInspdclr);
			b = "更新成功!";
		}
		return b;
	}

	//更新报检单-船东审核
	private String setUpdateInspdclrCd(ScsInspdclr scsInspdclr){
		String b;
		if(scsInspdclr.getInspnum()==null||scsInspdclr.getInspdate()==null||constMapper.findIdByInspnum(scsInspdclr.getInspnum(), scsInspdclr.getInspdate())==null){
			b = "此项目不存在!";
		}else if (scsInspdclr.getInspnum()==null||!chickInspnum(scsInspdclr.getInspnum())){
			b = "检验编号填写格式错误!";
		}else if (scsInspdclr.getCdopinion()==null||!chickPass(scsInspdclr.getCdopinion())) {
			b = "船东/建造代表意见格式填写错误!";
		}else if (scsInspdclr.getCd()==null||!chickPeoplename(scsInspdclr.getCd())) {
			b = "船东/建造代表填写错误!";
		}else {
			scsInspdclr.setIdstate("船东审核"+scsInspdclr.getCdopinion());
			scsInspdclr.setIdlatesttime(getNtime());
			scsInspdclr.setRq2(getNtime());
			ScsConstinsp scsConstinsp = new ScsConstinsp();
			scsConstinsp.setInspnum(scsInspdclr.getInspnum());
			scsConstinsp.setAllstate("报检单船东审核"+scsInspdclr.getCdopinion());
			scsConstinsp.setAlltime(getNtime());
			constMapper.updateIdCd(scsInspdclr);
			constMapper.updateAll(scsConstinsp);
			b = "更新成功!";
		}
		return b;
	}

	//更新报检单-验船师确认
	private String setUpdateInspdclrYcsconfirm(ScsInspdclr scsInspdclr){
		String b;
		if(scsInspdclr.getInspnum()==null||scsInspdclr.getInspdate()==null||constMapper.findIdByInspnum(scsInspdclr.getInspnum(), scsInspdclr.getInspdate())==null){
			b = "此项目不存在!";
		}else if(scsInspdclr.getInspnum()!=null&&constMapper.findIdByInspnum(scsInspdclr.getInspnum(), scsInspdclr.getInspdate()).getCdopinion()==null){
			b = "此项目船东未审核!";
		}else if (scsInspdclr.getInspnum()==null||!chickInspnum(scsInspdclr.getInspnum())){
			b = "检验编号填写格式错误!";
		}else if (scsInspdclr.getStatus()==null||!chickStatus(scsInspdclr.getStatus())) {
			b = "确认环节格式填写错误!";
		}else if (scsInspdclr.getStatus().equals("报检单填写无误")&&(!chickDate(scsInspdclr.getConfirmtime())||scsInspdclr.getConfirmtime()==null)) {
			b = "确认预约检验时间格式填写错误!";
		}else if(constMapper.findIdByInspnum(scsInspdclr.getInspnum(), scsInspdclr.getInspdate()).getConfirmtime()!=null&&constMapper.findIdByInspnum(scsInspdclr.getInspnum(), scsInspdclr.getInspdate()).getConfirmtime().equals(scsInspdclr.getConfirmtime())&&scsInspdclr.getConfirmtime()!=null&&!compareTime(scsInspdclr.getConfirmtime(),1)){
			b = "确认时间不能在当天之前!";
		}else if(constMapper.findIdByInspnum(scsInspdclr.getInspnum(), scsInspdclr.getInspdate()).getConfirmtime()==null&&scsInspdclr.getConfirmtime()!=null&&!compareTime(scsInspdclr.getConfirmtime(),1)){
			b = "确认时间不能在当天之前!";
		}else if (scsInspdclr.getYcs1()==null||!chickPeoplename(scsInspdclr.getYcs1())) {
			b = "验船师填写错误!";
		}else {
			if(scsInspdclr.getStatus().equals("报检单填写无误")){
				scsInspdclr.setIdstate("验船师已确认信息填写无误");
			}else{
				scsInspdclr.setIdstate("验船师已确认信息填写有误");
			}
			scsInspdclr.setIdlatesttime(getNtime());
			scsInspdclr.setRq3(getNtime());
			ScsConstinsp scsConstinsp = new ScsConstinsp();
			scsConstinsp.setInspnum(scsInspdclr.getInspnum());
			scsConstinsp.setAllstate("报检单"+scsInspdclr.getIdstate());
			scsConstinsp.setAlltime(getNtime());
			constMapper.updateIdYcsConfirm(scsInspdclr);
			constMapper.updateAll(scsConstinsp);
			b = "更新成功!";
		}
		return b;
	}

	//更新报检单-验船师检验
	private String setUpdateInspdclrYcscheck(ScsInspdclr scsInspdclr){
		String b;
		if(scsInspdclr.getInspnum()==null||scsInspdclr.getInspdate()==null||constMapper.findIdByInspnum(scsInspdclr.getInspnum(), scsInspdclr.getInspdate())==null){
			b = "此项目不存在!";
		}else if(scsInspdclr.getInspnum()!=null&&constMapper.findIdByInspnum(scsInspdclr.getInspnum(), scsInspdclr.getInspdate()).getStatus()==null){
			b = "此项目验船师未确认!";
		}else if (scsInspdclr.getInspopinion()==null||!chickInspopinion(scsInspdclr.getInspopinion())) {
			b = "检验意见格式填写错误!";
		}else if (scsInspdclr.getInspopinion().equals("通过")&&(scsInspdclr.getOpncontent()==null||scsInspdclr.getOpncontent().equals(""))) {
			b = "意见内容格式填写错误!";
		}else if (scsInspdclr.getInspopinion().equals("需整改")&&(scsInspdclr.getRectnum()==null||scsInspdclr.getRectnum().equals(""))) {
			b = "整改编号格式填写错误!";
		}else if (scsInspdclr.getInspopinion().equals("需整改")&&(scsInspdclr.getRectopinion()==null||scsInspdclr.getRectopinion().equals(""))) {
			b = "存在问题及整改意见格式填写错误!";
		}else if (scsInspdclr.getYcs2()!=null&&!chickPeoplename(scsInspdclr.getYcs2())) {
			b = "验船师填写错误!";
		}else if(scsInspdclr.getConfirmresult()==null){
			b = "确认整改结果格式填写错误!";
		}else if (!scsInspdclr.getConfirmresult().equals("")&&(scsInspdclr.getRectresult()==null||scsInspdclr.getRectresult().equals(""))) {
			b = "整改结果格式填写错误!";
		}else if (!scsInspdclr.getConfirmresult().equals("")&&!chickConfirmresult(scsInspdclr.getConfirmresult())) {
			b = "确认整改结果格式填写错误!";
		}else if (!scsInspdclr.getConfirmresult().equals("")&&(scsInspdclr.getYcs3()==null||!chickPeoplename(scsInspdclr.getYcs3()))) {
			b = "验船师填写错误!";
		}else {
			String idstate = constMapper.findIdByInspnum(scsInspdclr.getInspnum(), scsInspdclr.getInspdate()).getIdstate();
			if(idstate.equals("完成")||idstate.equals("整改完成")){
				constMapper.constCompleteDown(scsInspdclr.getInspnum());
			}
			if(scsInspdclr.getInspopinion().equals("通过")){
				scsInspdclr.setRectopinion("");
				scsInspdclr.setRectresult("");
				scsInspdclr.setRectnum("");
				scsInspdclr.setIdstate("完成");
				constMapper.constCompleteUp(scsInspdclr.getInspnum());
				constMapper.completeConst(scsInspdclr.getInspnum());
			}else{
				scsInspdclr.setOpncontent("");
				if(scsInspdclr.getConfirmresult()!=null&&scsInspdclr.getConfirmresult().equals("完成")){
					scsInspdclr.setIdstate("整改完成");
					constMapper.constCompleteUp(scsInspdclr.getInspnum());
				}else {
					scsInspdclr.setIdstate("需要整改");
				}
			}
			scsInspdclr.setIdlatesttime(getNtime());
			if(scsInspdclr.getConfirmresult()==null){
				scsInspdclr.setRq4(getNtime());
			}else {
				scsInspdclr.setRq5(getNtime());
			}
			ScsConstinsp scsConstinsp = new ScsConstinsp();
			scsConstinsp.setInspnum(scsInspdclr.getInspnum());
			scsConstinsp.setAllstate("报检单"+scsInspdclr.getIdstate());
			scsConstinsp.setAlltime(getNtime());
			constMapper.updateIdYcscheck(scsInspdclr);
			constMapper.updateAll(scsConstinsp);
			b = "更新成功!";
		}
		return b;
	}

	//更新报检单-验船师检验-船厂意见
	private String setUpdateIdCcopn(ScsInspdclr scsInspdclr){
		String b;
		if(scsInspdclr.getInspnum()==null||scsInspdclr.getInspdate()==null||constMapper.findIdByInspnum(scsInspdclr.getInspnum(), scsInspdclr.getInspdate())==null){
			b = "此项目不存在!";
		}else if(scsInspdclr.getInspnum()!=null&&constMapper.findIdByInspnum(scsInspdclr.getInspnum(), scsInspdclr.getInspdate()).getStatus()==null){
			b = "此项目验船师未确认!";
		}else if(!chickPass(scsInspdclr.getCcopn())){
			b = "船厂意见格式填写错误!";
		}else {
			Date date = new Date();
			DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
			String str = format.format(date);
			scsInspdclr.setCcopndate(str);
			constMapper.updateIdCcopn(scsInspdclr);
			b = "更新成功!";
		}
		return b;
	}

	//更新报检单-验船师检验-船东意见
	private String setUpdateIdCdopn(ScsInspdclr scsInspdclr){
		String b;
		if(scsInspdclr.getInspnum()==null||scsInspdclr.getInspdate()==null||constMapper.findIdByInspnum(scsInspdclr.getInspnum(), scsInspdclr.getInspdate())==null){
			b = "此项目不存在!";
		}else if(scsInspdclr.getInspnum()!=null&&constMapper.findIdByInspnum(scsInspdclr.getInspnum(), scsInspdclr.getInspdate()).getStatus()==null){
			b = "此项目验船师未确认!";
		}else if(!chickPass(scsInspdclr.getCdopn())){
			b = "船东意见格式填写错误!";
		}else {
			Date date = new Date();
			DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
			String str = format.format(date);
			scsInspdclr.setCdopndate(str);
			constMapper.updateIdCdopn(scsInspdclr);
			b = "更新成功!";
		}
		return b;
	}

	//删除报检单
	private String setDeleteId(String inspnum, String inspdate){
		String b;
		if(inspnum==null||inspdate==null||constMapper.findIdByInspnum(inspnum, inspdate)==null){
			b = "该项目不存在!";
		}else {
			String idstate = constMapper.findIdByInspnum(inspnum, inspdate).getIdstate();
			if(idstate.equals("完成")||idstate.equals("整改完成")){
				constMapper.constCompleteDown(inspnum);
			}
			constMapper.deleteId(inspnum, inspdate);
			b = "删除报检单成功!";
		}
		return b;
	}


	/*
	 * 其他操作
	 */
	//获取当前时间
	private Date getNtime(){
		Date date = new Date();
		return new Timestamp(date.getTime());
	}

	private String getSqbnum(){
		Date date = new Date();
		SimpleDateFormat matter=new SimpleDateFormat("yyyyMMddHHmmssSSS");
		return matter.format(date);
	}

	//比较日期 way==1,之后；way==0,之前
	private boolean compareTime(Date adate, int way){
		Date date = new Date();
		SimpleDateFormat matter=new SimpleDateFormat("yyyy-MM-dd");
		String comparedate = matter.format(date);
		String aadate = matter.format(adate);
		if(way==1){
			if(aadate.compareTo(comparedate)>=0){
				return true;
			}else {
				return false;
			}
		}
		if(way==0){
			if(aadate.compareTo(comparedate)<=0){
				return true;
			}else {
				return false;
			}
		}
		return false;
	}

	//检验日期格式
	private boolean chickDate(Date aDate){
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		String strDate = format.format(aDate);
		Pattern pattern = Pattern.compile("([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8])))");
		Matcher match=pattern.matcher(strDate);
		return match.matches();
	}

	//检验检验编号格式
	private boolean chickInspnum(String inspnum){
		Pattern pattern = Pattern.compile("^[A-Za-z0-9]{1,20}$");
		Matcher match=pattern.matcher(inspnum);
		return match.matches();
	}

	//检验邮编格式
	private boolean chickZipcode(String zipcode){
		Pattern pattern = Pattern.compile("^.{1,20}$");
		Matcher match=pattern.matcher(zipcode);
		return match.matches();
	}

	//检验报检单名称格式
	private boolean chickInspname(String inspname){
		Pattern pattern = Pattern.compile("^[0-9\u4e00-\u9fa5]{1,20}$");
		Matcher match=pattern.matcher(inspname);
		return match.matches();
	}

	//检验姓名
	private boolean chickPeoplename(String name){
		Pattern pattern = Pattern.compile("(^[\u4e00-\u9fa5]{2,4}$)|(^[a-zA-Z]{3,7}$)");
		Matcher match=pattern.matcher(name);
		return match.matches();
	}

	//检验验船师 船东 船厂 信息格式
	private boolean chickPeopleInfo(String info){
		Pattern pattern = Pattern.compile("(^[\u4e00-\u9fa5]{2,4}/1[345789]\\d{9}$)|(^[a-zA-Z]{3,7}/1[345789]\\d{9}$)");
		Matcher match=pattern.matcher(info);
		return match.matches();
	}

	//检验船厂 信息格式
	private boolean chickCcInfo(String info){
		Pattern pattern = Pattern.compile("(^[\u4e00-\u9fa5]{2,4}/\\d{1,20}$)|(^[a-zA-Z]{3,7}/\\d{1,20}$)");
		Matcher match=pattern.matcher(info);
		return match.matches();
	}

	//检验 单位名 船名 船籍港 设计单位 提交资料名称 申请单位名称 格式
	private boolean chickName(String name){
		Pattern pattern = Pattern.compile("^[\u4E00-\u9FA5A-Za-z0-9]{1,20}$");
		Matcher match=pattern.matcher(name);
		return match.matches();
	}

	//检验船名格式
	private boolean chickShipname(String shipname){
		Pattern pattern = Pattern.compile("^[\\s\u4E00-\u9FA5A-Za-z0-9]{1,20}$");
		Matcher match=pattern.matcher(shipname);
		return match.matches();
	}

	//船籍港 格式
	private boolean chickShipstops(String shipstops){
		Pattern pattern = Pattern.compile("^[\u4E00-\u9FA5]{1,20}$");
		Matcher match=pattern.matcher(shipstops);
		return match.matches();
	}

	//检验传真格式
	private boolean chickFax(String fax){
		Pattern pattern = Pattern.compile("^.{1,20}$");
		Matcher match=pattern.matcher(fax);
		return match.matches();
	}

	//检验 图号 审图批准号 格式 船厂工程编号
	private boolean chickNum(String num){
		Pattern pattern = Pattern.compile("^[A-Za-z0-9]{1,20}$");
		Matcher match=pattern.matcher(num);
		return match.matches();
	}

	//检验检验类型格式
	private boolean chickInsptype(String insptype){
		Pattern pattern = Pattern.compile("^[0-9A-Za-z\u4e00-\u9fa5]{1,10}$");
		Matcher match=pattern.matcher(insptype);
		return match.matches();
	}

	//检验航行区域格式
	private boolean chickRegion(String region){
		Pattern pattern = Pattern.compile("^[0-9A-Za-z\u4e00-\u9fa5]{1,10}$");
		Matcher match=pattern.matcher(region);
		return match.matches();
	}

	//检验总长 总吨位 主机功率 格式
	private boolean chickNumber(String number){
		Pattern pattern = Pattern.compile("^[1-9]\\d{0,7}\\.\\d{2}|0\\.\\d{2}$");
		Matcher match=pattern.matcher(number);
		return match.matches();
	}

	//总吨位格式
	private boolean chickGrosston(String number){
		Pattern pattern = Pattern.compile("^[1-9]\\d{0,6}$");
		Matcher match=pattern.matcher(number);
		return match.matches();
	}

	//检验社会信用统一代码格式
	private boolean chickCrecode(String crecode){
		Pattern pattern = Pattern.compile("^[0-9A-Z]{18}$");
		Matcher match=pattern.matcher(crecode);
		return match.matches();
	}

	//检验船厂地址
	private boolean chickCcadr(String ccadr){
		Pattern pattern = Pattern.compile("^[\u4e00-\u9fa5\\(\\)\\（\\）A-Za-z0-9]{2,30}$");
		Matcher match=pattern.matcher(ccadr);
		return match.matches();
	}

	//检验受理状态格式
	private boolean chickAuditstate(String auditstate){
		Boolean b = false;
		if(auditstate.equals("同意受理")||auditstate.equals("不予受理")){
			b = true;
		}
		return b;
	}

	//检验意见
	private boolean chickPass(String pass){
		Boolean b = false;
		if(pass.equals("通过")||pass.equals("不通过")){
			b = true;
		}
		return b;
	}

	//检验确认环节
	private boolean chickStatus(String status){
		Boolean b = false;
		if(status.equals("报检单填写无误")||status.equals("报检单填写有误")){
			b = true;
		}
		return b;
	}

	//检验检验意见
	private boolean chickInspopinion(String inspopinion){
		Boolean b = false;
		if(inspopinion.equals("通过")||inspopinion.equals("需整改")){
			b = true;
		}
		return b;
	}

	//确认整改结果
	private boolean chickConfirmresult(String confirmresult){
		Boolean b = false;
		if(confirmresult.equals("完成")||confirmresult.equals("未完成")){
			b = true;
		}
		return b;
	}

	//用户加入项目
	public void userJoinPro(String userid, String type){
		switch (type){
			case "验船师":
				userMapper.ycsJoinPro(userid);
				break;
			case "船厂":
				userMapper.ccJoinPro(userid);
				break;
			case "船东":
				userMapper.cdJoinPro(userid);
				break;
			default:
				break;
		}
	}

	//用户退出项目
	public void userQuitPro(String userid, String type){
		switch (type){
			case "验船师":
				userMapper.ycsQuitPro(userid);
				break;
			case "船厂":
				userMapper.ccQuitPro(userid);
				break;
			case "船东":
				userMapper.cdQuitPro(userid);
				break;
			default:
				break;
		}
	}

}